/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * TrainingBook
 * Copyright (C) Arnaud Duval 2010 <arnaud.duval@gmail.com>
 * 
 * TrainingBook is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * TrainingBook is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _O_S_M_MAP_TILE_CACHE_HPP_
#define _O_S_M_MAP_TILE_CACHE_HPP_

#include <gtkmm.h>
#include <string>

///@class OsmMapTileCache
///@brief Manage a cache for OSM tiles
class OsmMapTileCache
{
    public:
        ///@brief Default constructor
        OsmMapTileCache();
        ///@brief Constructor specifying the cache location and the tiles repository
        OsmMapTileCache(std::string, std::string tilesRepository="http://tile.openstreetmap.org/");
        ///@brief Destructor
        ~OsmMapTileCache();
        ///@brief Return the path to a specified tile
        std::string GetTile(int, int, int);
        ///@brief Dowload a specified tile to the cache
        bool DownloadCache(int, int, int);
        ///@brief Test if the specified tile is present in the cache
        bool IsInCache(int, int, int);
        ///@brief Set the tiles repository URL
        void SetTilesRepository(std::string);
        ///@brief Set the tiles cache URL
        void SetTilesCache(std::string);
        ///@brief Ensure that the cache directory corresponding to current directory is present
        void EnsureCachePath(std::string);
        ///@brief Return the parent directory of a given path
        std::string GetParentPath(std::string);
        ///@brief Set the status bar
        void SetStatusBar(Gtk::Statusbar*);
    protected:

    private:
        ///@brief Path to the cache directory (root path of cache)
        std::string cachePath;
        ///@brief Path to the cache directory of current repository (root path + repository name)
        std::string cachePathRepo;
        ///@brief Path to the tiles repository
        std::string tilesRepositoryPath;
        ///@brief Pointer to the status bar on which the information should be displayed
        Gtk::Statusbar *statusBar;

        ///@brief Overload of << operator
        friend std::ostream& operator<< (std::ostream&, const OsmMapTileCache&);
};

#endif // _O_S_M_MAP_TILE_CACHE_HPP_ //